package com.youlai.system.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.pagehelper.PageInfo;
import com.youlai.system.common.result.PageResult;
import com.youlai.system.model.query.CityQuery;
import com.youlai.system.model.vo.CityVO;
import com.youlai.system.service.CityService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springdoc.core.annotations.ParameterObject;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "14.城市接口")
@RestController
@RequestMapping("/api/v1/city")
@RequiredArgsConstructor
public class CityController {
    private final CityService cityService;
    @Operation(summary = "城市分页列表", security = {@SecurityRequirement(name = "Authorization")})
    @GetMapping("/page")
    public PageResult<CityVO> getCityPage(
            @ParameterObject CityQuery queryParams
    ){

        PageInfo<CityVO> pageInfo = cityService.getCityList(queryParams);

        // 将PageInfo对象转换为IPage对象
        Page<CityVO> iPage = new Page<>(pageInfo.getPageNum(), pageInfo.getPageSize());
        iPage.setRecords(pageInfo.getList());
        iPage.setTotal(pageInfo.getTotal());

        return PageResult.success(iPage);
    }
}
